<div class="layuimini-container">
    <form id="app-form" class="layui-form layuimini-form">
        <div class="layui-form-item  layui-row layui-col-xs12">
            <label class="layui-form-label required">复制门店</label>
            <div class="layui-input-block">
                <select name="store_id" id="storeId"  lay-filter="buildingFilter" data-select="{:url('management.store/getstore')}" data-fields="store_id,store_name">
                </select> 
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">复制类型</label>
            <div class="layui-input-block">
                <input type="radio" name="type" value="1" title="单商品" checked lay-filter="catetype">
                <!-- <input type="radio" name="type" value="2" title="分类"  lay-filter="catetype" > -->
            </div>
        </div>
        <div class="layui-form-item  layui-row layui-col-xs12 " id="good">
            <label class="layui-form-label required">商品</label>
            <div class="layui-input-block" id="dataTypes">
                <!-- <select name="products_id" id="productsId" lay-filter="houseIdFilter"  xm-select="example2_1">
                </select> -->
                <!-- <select name="select_base_cityname" id="select_base_cityname" lay-filter="select_base_cityname" xm-select="select_base_cityname" xm-select-type="1">
                    <option value=""></option>
                    <option value="1">北京</option>
                    <option value="2">上海</option>
                    <option value="3">天津</option>
                    <option value="4">重庆</option>
                </select> -->

            </div>
            <div class="layui-form-mid layui-word-aux">单次选择复制商品数量不宜过多，处理数据比较复杂过多会造成程序卡顿复制不成功</div>
        </div>
        <div class="layui-form-item  layui-row layui-col-xs12 layui-hide" id="cate">
            <!-- layui-hide -->
            <label class="layui-form-label required">分类</label>
            <div class="layui-input-block">
                <select name="cate_id" id="cateId" lay-filter="houseIdFilter" >
                </select>
            </div>
        </div>
        <div class="layui-form-item  layui-row layui-col-xs12">
            <label class="layui-form-label required">粘贴门店</label>
            <div class="layui-input-block">
                <select name="news_store_id"   data-select="{:url('management.store/getstore')}" data-fields="store_id,store_name">
                </select> 
            </div>
        </div>
        <div class="hr-line"></div>
        <div class="layui-form-item text-center">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit>确认</button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
        </div>

    </form>
</div>
<script src="__STATIC__/plugs/lay-v2.5.6/lay/modules/xm-select.js"></script>
<script>

//多选下拉框渲染对象
var dataTypes = null;
    //获取店铺下的分类
function getHousing(data) {
        var params={
            store_id:data.value
        }
        //检查项目添加到下拉框中
            $.ajax({
                url:"{:url('management.store_cate_price/getcate')}",
                dataType: 'json',
                data : JSON.stringify(params),
                contentType: "application/json",  
                type: 'post',
                success: function (data) {

                    $("#cateId").empty();//清空下拉框的值
                    $.each(data.data, function (index, item) {
                        $('#cateId').append(new Option(item.cate_name, item.cate_id));// 下拉菜单里添加元素
                    });
                    layui.form.render("select");//重新渲染 固定写法
                }
            });
};
    // 所选店铺下的商品
    function getGoods(data) {
        var params={
            store_id:data.value
        }
        var store_id=data.value
        //检查项目添加到下拉框中
            $.ajax({
                url:"{:url('platform.goods/getGoods')}",
                dataType: 'json',
                data : JSON.stringify(params),
                contentType: "application/json",  
                type: 'post',
                success: function (data) {
                    dataTypes = xmSelect.render({
                        el: '#dataTypes', 
                        toolbar: {
                            show: true,//是否展示工具条
                        },
                        name: 'products_id',
                        prop: {
                            name: 'products_title',
                            value: 'products_id',
                        },
                        autoRow: true,
                        filterable: true,
                        height: 'auto',
                        paging: true,
                        pageSize:7,
                        filterable: true,
                        data(){
                            return data.data//返回数据遵循官网指定结构
                        }
                    })	
                    // $("#productsId").empty();//清空下拉框的值
                    // $.each(data.data, function (index, item) {
                        // $('#productsId').append(new Option(item.products_title, item.products_id));// 下拉菜单里添加元素
                    // });
                    // layui.form.render("select");//重新渲染 固定写法
                }
            });
    };
    var layer = layui.layer,
        form = layui.form,
        $=layui.jquery,
        upload = layui.upload;
        var formSelects = layui.formSelects;
    // 联动
    layui.use(['form'], function(){
        form.on('select(buildingFilter)', function(data){
            getHousing(data);
            getGoods(data)
        });
        form.on('radio(catetype)', function(data){
            if(data.value==1){
                $("#cate").addClass('layui-hide');
                $("#good").removeClass('layui-hide');
                   
            }else{
                $("#good").addClass('layui-hide');
                $("#cate").removeClass('layui-hide');
            }
        });
    });
   
 
    // dataTypes = xmSelect.render({
    //                     el: '#dataTypes',
    //                     language: 'zn',
    //                     //工具栏
    //                     toolbar: {
    //                         show: true
    //                     },
    //                     filterable: true,//过滤搜索
    //                     paging: true,//分页
    //                     pageSize: 10,//每页条数
    //                     height: '500px',
    //                     //autoRow: true,//自动换行
    //                     url:"{:url('platform.goods/getGoods')}",
    //                     contentType: 'application/json',
    //                     method:'post',
    //                     request: {
    //                         store_id:3,
    //                     },
    //                     // data:  [
    //                     //       {name: '张三', value: 1},
    //                     //       {name: '李四', value: 2},
    //                     //       {name: '王五', value: 3},
    //                     //   ]
    //                 });
    // var valueStr = dataTypes.getValue('valueStr');

</script>